{* Модуль блока фильтров списка клиентов *}

<script type="text/javascript">
<!--{literal}
$(document).ready
(
    function()
    {
	$('select#filter').change
	(
	    function()
	    {
		$.blockUI({message:'Подождите...'});
		setTimeout(function(){$.unblockUI()},2000);
	    }
	);

	$('input#customer-name').autocomplete
	({
	    source:	'json/getDictionary.php'
			+ '?dictionary=customers'
			+ '&show_deleted=' + ( $('input#show_deleted').attr('checked') ? 1 : 0 )
			+ '&only_deleted=' + ( $('input#only_deleted').attr('checked') ? 1 : 0 ),
	    delay:	0,
	    select:	function(event,ui){$(this).val($(ui.item).val());$('form#customer-search').submit();}
	});

	$('input:checkbox.search-option').click(function(){$('form#customer-search').submit();});
	$('select#filter-print').change(function(){$('form#customer-search').submit();});
	$('a.q-clean').click(function(){$(this).prev().val('');});
	$('select#executive-id')
	    .change
	    (
		function()
		{
		    if ( $(this).val()!='' )
		    {
			$('select#filter-print').attr('disabled',false);
		    }
		    else
		    {
			$('select#filter-print').attr('disabled',true);
		    }
		}
	    )
	    .change();

// "Галки" фильтров по удаленным
	$('input:checkbox#show_deleted')
	    .click
	    (
		function()
		{
		    var only_deleted = $('input:checkbox#only_deleted');

		    $('input:text#customer-name')
			.autocomplete
			(
			    'option',
			    'source',
			    'json/getDictionary.php'
			    + '?dictionary=customers'
			    + '&show_deleted=' + ( $('input:checkbox#show_deleted').attr('checked') ? 1 : 0 )
			);

		    if ( $(this).attr('checked') )
		    {
			$(only_deleted)
			    .attr('disabled',false)
			    .parent()
				.removeClass('ui-state-disabled')
			    .click
			    (
				function()
				{
				    $('input:text#customer-name')
					.autocomplete
					(
					    'option',
					    'source',
					    'json/getDictionary.php'
					    + '?dictionary=customers'
					    + '&show_deleted=1'
					    + '&only_deleted=' + ( $('input:checkbox#only_deleted').attr('checked') ? 1 : 0 )
					);
				}
			    );
		    }
		    else
		    {
			$(only_deleted)
			    .attr('disabled',true)
			    .parent()
				.addClass('ui-state-disabled');
		    }
		}
	    );


    }
);
{/literal}-->
</script>

<!-- НАЧАЛО блока фильтров -->
<form method="get" id="customer-search">
    <input type="hidden" name="do" value="filter"/>
    <table class="ui-widget ui-state-default ui-corner-all" >
	<tr>
	    <th class="ui-widget-header" colspan="4">Блок фильтров</th>
	</tr>
	<tr>
	    <td align="right">Поиск:</td>
	    <td colspan="3"><input type="text" name="q" class="search" value="{$smarty.session.filter.customer_list.q|sslash|escape}" id="customer-name" style="width: 80%;"/><a href="javascript:void(0)" class="q-clean"><img src="images/icons/delete_16.png" border="0"/></a></td>
	</tr>
	<tr>
	    <td align="right">Номер договора:</td>
	    <td colspan="2"><input type="text" name="contract_num" class="search" value="{$smarty.session.filter.customer_list.contract_num|sslash|escape}" id="contract-num" style="width: 85%;"/><a href="javascript:void(0)" class="q-clean"><img src="images/icons/delete_16.png" border="0"/></a></td>
	    <td>&nbsp;</td>
	</tr>
	<tr>
	    <td align="right">
		<select name="field">
		    <option value="">&mdash;</option>
		    <optgroup label="Основные">
{*
			<option value="customer_name" {if not empty ($smarty.session.filter.customer_list.field) && $smarty.session.filter.customer_list.field=='customer_name'}selected{/if}>Название организации</option>
*}
			<option value="email" {if not empty ($smarty.session.filter.customer_list.field) && $smarty.session.filter.customer_list.field=='email'}selected{/if}>E-Mail</option>
			<option value="inn" {if not empty ($smarty.session.filter.customer_list.field) && $smarty.session.filter.customer_list.field=='inn'}selected{/if}>ИНН</option>
		    </optgroup>
		    <optgroup label="Дополнительные">
		    {foreach from=$customs item=f}
			<option value="{$f.id}" {if $smarty.session.filter.customer_list.field==$f.id}selected{/if}>{$f.title}</option>
		    {/foreach}
		    </optgroup>
		</select>
	    </td>
	    <td colspan="2"><input type="text" name="field_value" class="search" value="{$smarty.session.filter.customer_list.field_value|sslash|escape}" id="contract-num" style="width: 85%;"/><a href="javascript:void(0)" class="q-clean"><img src="images/icons/delete_16.png" border="0"/></a></td>
	    <td>&nbsp;</td>
	</tr>
	{if $smarty.session.manager.is_admin==1}
	<tr>
	    <td align="right">Менеджер:</td>
	    <td colspan="3">
		<select name="manager_id">
		    <option value="">&mdash;</option>
		    {foreach from=$managers item=manager}
		    <option value="{$manager.id}" {if $smarty.session.filter.customer_list.manager_id==$manager.id}selected{/if} {if $manager.is_deleted==1}style="background-color:red; color:white;"{/if}>{$manager.manager_name}</option>
		    {/foreach}
		</select>
	    </td>
	</tr>
	{/if}
	<tr>
	    <td align="right">Группа:</td>
	    <td>
		<select name="group_id">
		    <option value="">&mdash;</option>
		    {foreach from=$groups item=group}
		    <option value="{$group.id}" {if $smarty.session.filter.customer_list.group_id==$group.id}selected{/if}>{$group.group_name}</option>
		    {/foreach}
		</select>
	    </td>
	    <td align="right">Статус:</td>
	    <td>
		<select name="status_id">
		    <option value="">&mdash;</option>
		    {foreach from=$statuss item=status}
		    <option value="{$status.id}" {if $smarty.session.filter.customer_list.status_id==$status.id}selected{/if}>{$status.status_name}</option>
		    {/foreach}
		</select>
	    </td>
	</tr>
	<tr>
	    <td align="right">Исполнитель:</td>
	    <td colspan="2">
		<select name="executive_id" id="executive-id">
		    <option value="">&mdash;</option>
		{foreach from=$executives item=executive}
		    <option value="{$executive.id}" {if $smarty.session.filter.customer_list.executive_id==$executive.id}selected{/if}>{$executive.executive_name|sslash}</option>
		{/foreach}
		</select>
	    </td>
	    <td>
		<select name="documents" id="filter-print">
		    <option value="">&mdash;</option>
		    <option value="complete" {if $smarty.session.filter.customer_list.documents=='complete'}selected{/if} class="ui-state-highlight">Документы загружены</option>
		    <option value="no-complete" {if $smarty.session.filter.customer_list.documents=='no-complete'}selected{/if} class="ui-state-error">Документы не загружены</option>
		    <option value="printed" {if $smarty.session.filter.customer_list.documents=='printed'}selected{/if} class="ui-state-default">Документы распечатаны</option>
		    <option value="no-printed" {if $smarty.session.filter.customer_list.documents=='no-printed'}selected{/if} class="ui-state-disabled">Документы не распечатаны</option>
		</select>
	    </td>
	</tr>

	<tr>
	    <td align="right">Зарегистрирован:</td>
	    <td colspan="3">с <input type="text" class="date" name="create_date_begin" value="{$smarty.session.filter.customer_list.create_date_begin}"/> по <input type="text" name="create_date_end" class="date" value="{$smarty.session.filter.customer_list.create_date_end}"/></td>
	</tr>

	<tr>
	    <td>&nbsp;</td>
	    <td colspan="3">
		<ul style="list-style-type: none;">
		    <li>
			<input type="checkbox" name="show_deleted" value="1" id="show_deleted" {if $smarty.session.filter.customer_list.show_deleted==1}checked{/if}/>
			<label for="show_deleted">Показывать и искать среди удалённых</label>
		    </li>
		    <li {if empty($smarty.session.filter.customer_list.show_deleted)}class="ui-state-disabled"{/if}>
			<input type="checkbox" name="only_deleted" value="1" id="only_deleted" {if $smarty.session.filter.customer_list.only_deleted==1}checked{/if} {if empty($smarty.session.filter.customer_list.show_deleted)}disabled{/if}/>
			<label for="only_deleted"><u>Только</u> удаленные</label>
		    </li>
		</ul>
	    </td>
	</tr>
	<tr>
	    <td colspan="4" align="center">
		<input type="submit" class="button" value="Применить фильтр"/>
	    </td>
	</tr>
    </table>
</form>
<!-- КОНЕЦ блока фильтров -->
